home *** CD-ROM | disk | FTP | other *** search
- Path: doors.informatik.uni-siegen.de!plrunu
- From: plrunu@informatik.uni-siegen.de (Runu Knips)
- Newsgroups: comp.lang.c++
- Subject: Re: using template
- Date: 15 Mar 1996 12:39:16 GMT
- Organization: University of Siegen
- Sender: plrunu@doors.informatik.uni-siegen.de (Runu Knips)
- Message-ID: <4ibodk$br5@si-nic.hrz.uni-siegen.de>
- References: <31415360.2A20@bass.com.my>
- NNTP-Posting-Host: doors.informatik.uni-siegen.de
-
- In article <31415360.2A20@bass.com.my>, Thomas Chai <jhchai@bass.com.my> writes:
- |> include <iostream.h>
- |>
- |> template <class T> class STACK {
- |> int stackidx;
- |> T stack[100];
- |> public :
- |> STACK() { stackidx = 0; }
- |> void push(T entry) { stack[stackidx++] = entry; }
- |> T pop() { return stack[--stackidx]; }
- |> };
- |>
- |> main()
- |> {
- |> STACK<float> s1;
- |>
- |> s1.push(32.12);
- |> s1.push(1.092);
- |> cout << "pop = " << s1.pop() << "\n";
- |> cout << "pop = " << s1.pop() << "\n";
- |> cout << "pop = " << s1.pop() << "\n";
- |> }
- |>
- |>
- |> Hi,
- |>
- |> for the example above how do I make use of the
- |> STACK class to push and pop using data type (char *)
- |>
- |> I try using STACK<char *> s1...but the compiler complains
-
-
- Ooops, my compilers accept this...
-
- Maybe try 'typedef char *string;' and then STACK<string> ?
-
- Nevertheless, it seems to be a bug of your compiler if it
- didn't accept this. Try g++, for example :*).
-
-